package top.wardyan.wbaseswt.control;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

import top.wardyan.wbaseswt.conf.Const;

public class WButton extends Button{

	
	public WButton(Composite parent, int style) {
		super(parent, style);
		this.createContent();
	}
	
	public WButton(Composite parent, int style, int x, int y, int width, int height, String text, SelectionListener adapter) {
		this(parent, style);
		this.setBounds(x, y, width, height);
		if(text != null)
			this.setText(text);
		if(adapter != null) {
			this.addSelectionListener(adapter);
		}
	}
	
	public WButton(Composite parent, int x, int y, int width, int height, String text, SelectionListener adapter) {
		this(parent, SWT.NONE, x, y, width, height, text, adapter);
	}
	
	public WButton(Composite parent, int style, String text, SelectionListener adapter) {
		this(parent, style, text, adapter, (FormData)null);
	}
	
	public WButton(Composite parent, int style, String text, SelectionListener adapter, FormData formdata) {
		this(parent, style);
		if(text != null)
			this.setText(text);
		if(adapter != null) {
			this.addSelectionListener(adapter);
		}
		if(formdata != null) {
			this.setLayoutData(formdata);
		}
	}
	
	public WButton(Composite parent, int style, String text, SelectionListener adapter, WFormData formdata) {
		this(parent, style, text, adapter, formdata.getFormData());
	}
	
	
	private void createContent() {
		this.setFont(Const.getDefaultFont());
	}
	
	
	/**
	 * 取得控件右下角的定点的x
	 * @return
	 */
	public int getVertexX() {
		return this.getLocation().x + this.getSize().x;
	}
	/**
	 * 取得控件右下角的定点的y
	 * @return
	 */
	public int getVertexY() {
		return this.getLocation().y + this.getSize().y;
	}
	@Override
	protected void checkSubclass() {}
}
